//
//  YMListCell.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/3/18.
//

import SwiftUI

struct YMListCell: View {
    @State var isDetailActive :Bool = false
    @State var book :YMBook
    @State var width :CGFloat = SCREEN_WIDTH
    var body: some View {
        VStack {
            NavigationLink(destination: YMDetailView(bookId: book.bookId ?? "")) {
                HStack(alignment: .top, spacing: 15) {
                    WebImage(url: URL(string: book.cover?.cover ?? "")).resizable().placeholder {
                        RoundedRectangle(cornerRadius:5).foregroundColor(.gray)
                    }.indicator(.activity).transition(.fade).cornerRadius(5).frame(width: 80, height: 105, alignment: .center).padding(EdgeInsets(top: 12, leading: 0, bottom: 12, trailing: 0))
                    HStack {
                        VStack(alignment: .leading, spacing: 10) {
                            Text(book.title ?? "").foregroundColor(Color.appx000000()).padding(EdgeInsets.init(top: 5, leading: 0, bottom: 0, trailing: 0)).font(Font(UIFont.systemFont(ofSize: 17, weight: .medium))).lineLimit(1)
                            HStack(alignment: .center, spacing: 10) {
                                Text("作者:\(book.author ?? "")").foregroundColor(Color.appx333333()).font(.system(size: 15)).lineLimit(1)
                                Spacer()
                                if book.minorCate.count > 0{
                                    Text(book.minorCate).padding(EdgeInsets(top: 3, leading: 6, bottom: 3, trailing: 6)).foregroundColor(Color.appx999999()).font(.system(size: 12)).lineLimit(1).overlay(RoundedRectangle(cornerRadius: 3, style: .continuous).stroke(AppXDDDDDD, lineWidth: 1))
                                    
                                }
                            }
                            Text(book.shortIntro?.stringByTrim() ?? "").foregroundColor(Color.appx999999()).font(.system(size: 15)).lineLimit(2)
                        }.padding(EdgeInsets(top: 12, leading: 0, bottom: 12, trailing: 0))
                    }
                }.frame(width: width - 30, height: 130, alignment: .leading)
            }
        }
    }
}
